<?php 
namespace Admin\Model;

use Think\Model\RelationModel;

class BlogModel extends RelationModel{
    
    protected $tableName = 'blog';
    
    protected $_link = array(
        'tags' => array(
            'mapping_type' => self::MANY_TO_MANY,
            'class_name' => 'blog',
            'mapping_name' => 'tags',
            'foreign_key' => 'id',
            'relation_foreign_key' => 'art_id',
            'relation_table' => 'blog_article_key',
        )
    );
    
    // 设置自动验证时的规则
    protected $_validate = array(
        array('title','require','博客标题不能为空'),
        array('cat_id','0','',1,'notequal'),
        array('time','require','博客发布时间不能为空'),
    );
    
    // 设置自动添加
    protected $_auto = array(
        array('count','getCount',3,'callback'),
    );
    
    // 自动添加时调用的函数
    public function getCount(){
        
        return mt_rand(100,200);
    }
}
?>